package com.muyu.cloud.system.controller;

import com.muyu.cloud.system.domain.UserInfo;
import com.muyu.cloud.system.service.UserInfoService;
import com.muyu.common.result.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: DongZeLiang
 * @date: 2024/5/24
 * @Description: 用户信息控制层
 * @Version: 1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user-info")
public class UserInfoController {

    private final UserInfoService userInfoService;

    /**
     * 通过用户名称查询用户信息
     * @param userName 用户名称
     * @return 用户信息
     */
    @GetMapping("/by/user-name/{userName}")
    public Result<UserInfo> findByuserName(@PathVariable("userName") String userName) {
        return Result.success(userInfoService.selectByuserName(userName));
    }

    /**
     * 用户修改
     * @param userInfo
     * @return
     */
    @PostMapping("upd")
    public Result upd(@RequestBody UserInfo userInfo){
        Integer upd = userInfoService.upd(userInfo);
        return Result.success(upd);
    }

    /**
     * 查询用户信息
     * @param userInfo
     * @return
     */
    @PostMapping("userList")
    public Result<List<UserInfo>> userList(@RequestBody UserInfo userInfo){
        List<UserInfo> userInfos = userInfoService.userList(userInfo);
        return Result.success(userInfos);
    }
}
